<?php
/*
Resdap ajax snippets page
-------------------------
Should be called with /ajax?a=aResdapAjaxAction
can return anything

part of the ResDaP platform.
*/
include 'functions.php';

if (!isset($_GET['a'])) {
	//seems like someone's trying to trick us...
	header('Refresh: 0; URL=http://resources.scratchr.org/');
	die();
}

$action = $_GET['a'];
switch ($action) {
	case 'showresource':
		if ($resdap_mod_features && isset($_GET['id'])) {
			$id = $_GET['id'];
			resdap_connect();
			$q = "UPDATE res_resources SET hide=0 WHERE id='$id'";
			$result = mysql_query($q);
		}
		break;
	case 'hideresource':
		if ($resdap_mod_features && isset($_GET['id'])) {
			$id = $_GET['id'];
			resdap_connect();
			$q = "UPDATE res_resources SET hide=1 WHERE id='$id'";
			$result = mysql_query($q);
		}
		break;
	case 'checkscratchruser':
		if (isset($_GET['n'])) {
			//$userexists = file_get_contents('http://scratch.mit.edu/users/'.$_GET['n'] );
			$httpheaders = get_headers('http://scratch.mit.edu/users/'.$_GET['n']);
			if (strpos($httpheaders[0], '200')) {
				echo 'v';
			} else {
				echo 'u';
			}
		}
		break;
}
?>